home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / DirectX / dxsdk_oct2004.exe / dxsdk.exe / Samples / C++ / Direct3D / StateManager / skybox01.fx < prev    next >
Encoding:
Text File  |  2004-09-27  |  3.4 KB  |  110 lines

  1. //--------------------------------------------------------------------------------------
  2. //
  3. // Skybox Lighting Model
  4. // Copyright (c) Microsoft Corporation. All rights reserved.
  5. //
  6. //--------------------------------------------------------------------------------------
  7.  
  8. //--------------------------------------------------------------------------------------
  9. // Effect Edit defaults
  10. //--------------------------------------------------------------------------------------
  11.  
  12. string XFile = "skybox01.x";     // model
  13. int    BCLR = 0xff202080;        // background
  14.  
  15.  
  16. //--------------------------------------------------------------------------------------
  17. // Scene Setup
  18. //--------------------------------------------------------------------------------------
  19.  
  20. // There is no lighting information,
  21. // as the skybox texture is pre-lit
  22.  
  23. // matrices
  24. matrix matView  : VIEW;
  25. matrix matProj  : PROJECTION;
  26.  
  27.  
  28. //--------------------------------------------------------------------------------------
  29. // Material Properties
  30. //--------------------------------------------------------------------------------------
  31.  
  32. // Texture Parameter, annotation specifies default texture for EffectEdit
  33. texture Texture0 <  string type = "CUBE"; string name = "skybox02.dds"; >;
  34.  
  35. // Sampler, for sampling the skybox texture
  36. sampler linear_sampler = sampler_state
  37. {
  38.     Texture   = (Texture0);
  39.     MipFilter = LINEAR;
  40.     MinFilter = LINEAR;
  41.     MagFilter = LINEAR;
  42. };
  43.  
  44.  
  45. //--------------------------------------------------------------------------------------
  46. // Vertex Shader
  47. //--------------------------------------------------------------------------------------
  48. void VS ( in  float3 v0   : POSITION,
  49.           out float4 oPos : POSITION,
  50.           out float3 oT0  : TEXCOORD0 )
  51. {
  52.     // Strip any translation off of the view matrix
  53.     // Use only rotations & the projection matrix
  54.     float4x4 matViewNoTrans =
  55.     {
  56.         matView[0],
  57.         matView[1],
  58.         matView[2],
  59.         float4( 0.f, 0.f, 0.f, 1.f )
  60.     };
  61.  
  62.     // Output the position
  63.     oPos = mul( float4(v0,1.f), mul( matViewNoTrans, matProj ) );
  64.     
  65.     // Calculate the cube map texture coordinates
  66.     // Because this is a cube-map, the 3-D texture coordinates are calculated
  67.     // from the world-position of the skybox vertex.
  68.     // v0 (from the skybox mesh) is considered to be pre-transformed into world space
  69.     oT0 = v0;
  70. }
  71.  
  72.  
  73.  
  74.  
  75. //--------------------------------------------------------------------------------------
  76. // Pixel Shader
  77. //--------------------------------------------------------------------------------------
  78. void PS( in  float3 t0 : TEXCOORD0,
  79.          out float4 r0 : COLOR0 )
  80. {
  81.     // The skybox texture is pre-lit, so simply output the texture color
  82.     r0 = tex3D( linear_sampler, t0 );
  83. }
  84.  
  85.  
  86.  
  87.  
  88.  
  89. //--------------------------------------------------------------------------------------
  90. // Default Technique
  91. // Establishes Vertex and Pixel Shader
  92. // Ensures base states are set to required values
  93. // (Other techniques within the scene perturb these states)
  94. //--------------------------------------------------------------------------------------
  95. technique tec0
  96. {
  97.     pass P0
  98.     {
  99.         VertexShader = compile vs_1_1 VS();
  100.         PixelShader  = compile ps_1_4 PS();
  101.         
  102.         ZEnable = FALSE;
  103.         ZWriteEnable = FALSE;
  104.         AlphaBlendEnable = FALSE;
  105.         CullMode = CCW;
  106.         AlphaTestEnable = FALSE;
  107.     }
  108. }
  109.  
  110.